<template>
  <div class="searchbar">
    <i class="iconfont icon-tubiaozhizuomoban"></i>
    <input
      ref="input"
      :value="keyCode"
      v-on:input="updateValue($event.target.value)" 
      placeholder="请输入关键词">
    <i ref="icon1" 
       style="color: #AAA;display: none" 
       @click="updateValue('')" 
       class="iconfont icon-guanbi2fill"></i>
    <i ref="icon2"></i>
  </div>
</template>

<script>
export default {
  name: 'searchbar',
  props: {
    keyCode: {
      type: String,
      default: ''
    }
  },
  components: {

  },
  data () {
    return {
      data: '',
      isClean: true
    }
  },
  methods: {
    updateValue (value) {
      if (value === '') {
        this.$refs.input.value = ''
        this.$refs.icon1.style.display = 'none'
        this.$refs.icon2.style.display = 'flex'
      } else {
        this.$refs.icon1.style.display = 'flex'
        this.$refs.icon2.style.display = 'none'
      }
      this.$emit('input', value)
    }
  },
  created () {

  }
}
</script>

<style scoped lang="less">
.searchbar {
  background: white;
  border: 1px solid rgba(102,102,102,0.20);
  border-radius: 4px;
  height: 2.25em;
  width: 93%;
  display: flex;
  input {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    border: none;
    flex: 8;
  }
  i {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  i:nth-child(1) {
    font-size: 1.5em;
  }
}
input::-webkit-input-placeholder {
  color: rgba(102,102,102,0.50);
}
</style>